/*********************************************************************************
 *      Copyright:  (C) 2022 YanlinZhou<1222>
 *                  All rights reserved.
 *
 *       Filename:  log.h
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(04/18/2022)
 *         Author:  YanlinZhou <1222>
 *      ChangeLog:  1, Release initial version on "04/18/2022 08:20:38 PM"
 *                 
 ********************************************************************************/

#ifndef  _LOG_H_
#define  _LOG_H_

#include<stdlib.h>
#include <unistd.h>

#define LOG_ROLLBACK_SIZE           5*1000000   /* Default rollback log size 5M Bytes */
#define LOG_NAME 					"./temp/running.log"


/*
 * log level
 */
enum 
{
	LOG_LEVEL_ERROR,
	LOG_LEVEL_WARN,
	LOG_LEVEL_INFO,
	LOG_LEVEL_DEBUG,
	LOG_LEVEL_MAX,
};

/*
 * log prefix string for different logging levels
 */
#define LOG_STRING_ERROR  "ERROR"
#define LOG_STRING_WARN   "WARN "
#define LOG_STRING_INFO   "INFO "
#define LOG_STRING_DEBUG  "DEBUG"


/*
 * logger initial and terminate functions
 */
int logger_init(char *filename, int loglevel);
void logger_term(void);

/*
 * logging methods by levels
 */
void log_error(char* format, ...);
void log_warn(char* format, ...);
void log_info(char* format, ...);
void log_debug(char* format, ...);
int open_my_log(int debug);
int check_and_rollback();

#endif   /* ----- #ifndef _LOGGER_H_  ----- */
